package com.vegetable.modules.service.baseData.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.Query;
import com.vegetable.modules.entity.baseData.BaseDict;
import com.vegetable.modules.mapper.baseData.BaseDictMapper;
import com.vegetable.modules.service.baseData.IBaseDictService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 基础数据 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-04
 */
@Slf4j
@Service
@AllArgsConstructor
public class BaseDictServiceImpl extends ServiceImpl<BaseDictMapper, BaseDict> implements IBaseDictService {

    /**
     * 基础数据
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String dictType = (String)params.get("dictType");
        String valueOne = (String)params.get("valueOne");
        String valueTwo = (String)params.get("valueTwo");
        IPage<BaseDict> page = this.page(
                new Query<BaseDict>().getPage(params),
                new QueryWrapper<BaseDict>()
                        .eq(StringUtils.isNotBlank(dictType),"dict_type", dictType)
                        .like(StringUtils.isNotBlank(valueOne),"value_one", valueOne)
                        .eq(StringUtils.isNotBlank(valueTwo),"value_two", valueTwo)
                        .orderByDesc("create_time")
        );

        return new PageUtils(page);
    }

    @Override
    public List<BaseDict> queryGoodsType() {
        Map<String, Object> params = new HashMap<>();
        params.put("dictType", "goods_type");
        params.put("limit", "1000");
        PageUtils pu = queryPage(params);
        return (List<BaseDict>) pu.getList();
    }
}
